

//
//  ScrollViewController.m
//  WD-Movies
//
//  Created by 贺泌钦 on 2019/1/23.
//  Copyright © 2019 chuck. All rights reserved.
//

#import "ScrollViewController.h"
#import "MainViewController.h"

@interface ScrollViewController ()<UIScrollViewDelegate>
{
    //实现三个属性
    
    UIScrollView *scroll;
    
    NSArray *imgArr;//图片
    
    UIPageControl *page;//页面
}
@end

@implementation ScrollViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    scroll = [[UIScrollView alloc]initWithFrame:self.view.frame];
    
    //添加协议
    
    scroll.delegate = self;
    [self.view addSubview:scroll];
    imgArr = @[@"1",@"2",@"3",@"icon"];
    //设置图片进行滚动
    scroll.pagingEnabled = YES;
    for (int i = 0; i < imgArr.count; i++)
    {
        UIImageView *img = [[UIImageView alloc]initWithFrame:CGRectMake(self.view.frame.size.width * i, 30, self.view.frame.size.width,self.view.frame.size.width)];
        img.userInteractionEnabled = YES;
        if (i == imgArr.count - 1)
        {
            UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
            btn.frame = CGRectMake((self.view.frame.size.width-100)/2, 600, 100, 50);
            [btn setTitle:@"戳我进入" forState:UIControlStateNormal];
            [btn addTarget:self action:@selector(Click) forControlEvents:UIControlEventTouchUpInside];
            btn.layer.cornerRadius = 10;
            btn.layer.masksToBounds = YES;
            btn.backgroundColor = [UIColor whiteColor];
            [img addSubview:btn];

        }
        img.image = [UIImage imageNamed:imgArr[i]];
        [scroll addSubview:img];
    }
    scroll.contentSize = CGSizeMake(self.view.frame.size.width * imgArr.count, self.view.frame.size.height);
    //取消弹簧效果
    scroll.bounces = NO;
    //隐藏滚动条
    scroll.showsHorizontalScrollIndicator = NO;

    
}

#pragma mark -UIScrollViewDelegate
-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    //求余
    NSInteger index = scroll.contentOffset.x / scrollView.frame.size.width;
    page.currentPage = index;
}

- (void)Click
{
    MainViewController *main = [MainViewController new];
    [self presentViewController:main animated:YES completion:nil];
}


@end
